package com.supermap.fabricsdk;

import java.util.UUID;
import java.util.logging.Logger;

public class SmTestThreadWrite extends Thread {

    Logger logger = Logger.getLogger(SmTestThreadWrite.class.getName());
    private SmChain smChain;
    private String chaincodeName;
    private int number;
    private int threadCount;

    public SmTestThreadWrite(SmChain smChain, String chaincodeName, int number, int i) {
        this.smChain = smChain;
        this.chaincodeName = chaincodeName;
        this.number = number;
        this.threadCount = i;
    }

    @Override
    public void run() {
        String result = null;
        for (int i = 0; i < number; i++) {
            String Key = UUID.randomUUID().toString();
            String Value = Key;
            result = smChain.getTransaction().invokeByString(
                    chaincodeName,
                    "PutStringRecordByKey",
                    new String[]{Key, Value}
            );
            if ( result.length() == 0) {
                logger.info("Put data on chain FAILED! transactionID :" + result);
            }
        }
        System.out.println("执行完第" + this.threadCount + "线程");
    }
}
